﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using GBlason.ViewModel;
using GBlason.ViewModel.CoatOfArm;
using GBlason.ViewModel.Contract;

namespace GBlason.Common.TemplateSelector
{
    public class PropertyTable : DataTemplateSelector
    {
        private static Dictionary<Type, DataTemplate> AvailableTypeSwitch = new Dictionary<Type, DataTemplate>();

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (item is PropertyDisplayer)
            {
                var propDis = item as PropertyDisplayer;
                if (AvailableTypeSwitch.ContainsKey(propDis.PropertyValueType))
                    return AvailableTypeSwitch[propDis.PropertyValueType];
            }
            return null;
        }

        public PropertyTable()
        {
            if (!App.IsInDesignMode)
            {
                AvailableTypeSwitch = new Dictionary<Type, DataTemplate>
                {
                    {
                        typeof(ShapeViewModel),
                        Application.Current.MainWindow.FindResource("PropertyTableCellItemTemplate") as DataTemplate
                    },
                    {
                        typeof(TinctureViewModel),
                        Application.Current.MainWindow.FindResource("PropertyTableColorSelectorItemTemplate") as DataTemplate
                    }
                };
            }
        }
    }
}
